package org.example.springaitest.controller;


import org.example.springaitest.tools.Tool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
class MyController {
    private final ChatClient chatClient;
    private final Tool tool;
    public MyController(Tool tool, ChatClient chatClient) {
        this.tool = tool;
        this.chatClient = chatClient;
    }
    @GetMapping(value="/ai", produces = "text/html;charset=utf-8")
    public Flux<String> generation(@RequestParam String userInput) {
        Flux<String> output = chatClient.prompt()
                .user(userInput)
                .tools(tool)
                .stream()
                .content();
        return output;
    }

}